﻿using MCPlatform.Builder.WorkStation;
using MCPlatform.Communicate.Modbus;
using MCPlatform.Communicate.TcpIp;
using MCPlatform.Models;
using MCPlatform.MotionLib.Base.AssitantClass;
using MCPlatform.MotionLib.Base.Environment;
using MCPlatform.UI.Components;
using MCPlatform.UI.Controls.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MCPlatform.Builder;
using MCPlatform.Communicate.SerialPorts;

namespace MCPlatform.ViewModels.Shell
{
    public class CommunicateViewModel : ViewModelBase
    {
        public CommunicateViewModel()
        {

            //SerialPortModelItems = new ObservableCollection<SerialPortModel>
            //    (ReadConfigData.GetParaConfigs<SerialPortModel>(Paths.ComConfigPaths) ?? new List<SerialPortModel>());
            //foreach (var serialPort in SerialPortModelItems)
            //{
            //    serialPort.MappingComInfoToSerialPort();
            //    serialPort.ISerialPort?.OpenSerialPort();
            //}
          
      

            //ModbusTCPModelItems = new ObservableCollection<ModbusTCPModel>
            //     (ReadConfigData.GetParaConfigs<ModbusTCPModel>(Paths.ModbusTcpConfigPaths) ?? new List<ModbusTCPModel>());

           

            TcpClientModelItems = new ObservableCollection<TcpClientModel>
                  (ReadConfigData.GetParaConfigs<TcpClientModel>(Paths.TcpClientConfigPaths) ?? new List<TcpClientModel>());

            CuttingStation.NTcpClient = TcpClientModelItems[0].NTcpClient;


            CuttingStation.NTcpClient.Connect();

        }



        #region Properties

        private ObservableCollection<SerialPortModel>? _SerialPortModelItems;

        public ObservableCollection<SerialPortModel>? SerialPortModelItems
        {
            get { return _SerialPortModelItems; }
            set
            {
                _SerialPortModelItems = value;
            }
        }

        private static ObservableCollection<ModbusTCPModel> _ModbusTCPModelItems = new ObservableCollection<ModbusTCPModel>();

        public static ObservableCollection<ModbusTCPModel> ModbusTCPModelItems
        {
            get { return _ModbusTCPModelItems; }
            set
            {
                _ModbusTCPModelItems = value;
            }
        }


        private ObservableCollection<TcpClientModel>? _TcpClientModelItems;

        public ObservableCollection<TcpClientModel>? TcpClientModelItems
        {
            get { return _TcpClientModelItems; }
            set
            {
                _TcpClientModelItems = value;
            }
        }



        #endregion

        #region Methods



        #endregion
    }
}